package org.example;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class immutable_Demo2 {
    public static void main(String[] args) {
        HashMap<String,String> map=new HashMap<>();
        map.put("A","a");
        map.put("B","b");
        map.put("C","c");
        map.put("D","d");

        Set<Map.Entry<String, String>> entries = map.entrySet();

        Map.Entry[] arr1=new Map.Entry[entries.size()];
        Map.Entry[] arr2 = entries.toArray(arr1);

        //不可变集合 键值对象不能超过10个 否则用ofEntries
        Map map1=Map.ofEntries(arr2);
        System.out.println(map1);
        System.out.println("===============");

        //简化1
        Map<Object,Object> arr3 = Map.ofEntries(map.entrySet().toArray(new Map.Entry[map.size()]));
        System.out.println(arr3);
        System.out.println("===============");
        //简化2
        Map<String,String> map2=Map.copyOf(map);
        System.out.println(map2);
    }
}
